package or.exa.cangguan.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import or.exa.cangguan.common.Page;
import or.exa.cangguan.common.Result;
import or.exa.cangguan.entity.dto.GoodsDto;
import or.exa.cangguan.entity.vo.InOperationVo;
import or.exa.cangguan.service.InOperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.PrintWriter;
import java.util.List;

@Api(tags = "入库作业单")
@RestController
public class InOperationController {



    @Autowired
    private InOperationService inOperationService;



    //查询入库作业单
    @ApiOperation("查询入库作业单")
    @PostMapping("/inOperation/search")
    public Result searchInOperation(@RequestBody InOperationVo inOperationVo){

        Page page = inOperationService.searchInOperation(inOperationVo);

        return Result.ok(page);
    }


    //新增入库作业单
    @ApiOperation("新增入库作业单")
    @PostMapping("/inOperation/add")
    public Result addInOperation(@RequestBody InOperationVo inOperationVo){
        Integer i = inOperationService.addInOperation(inOperationVo);
        return i>0?Result.ok("添加成功"):Result.ok("添加失败");
    }


    //更新作业单
    @ApiOperation("更新作业单")
    @PostMapping("/inOperation/update")
    public Result updateInOperation(@RequestBody InOperationVo inOperationVo){

        Integer i = inOperationService.updateInOperation(inOperationVo);

        return i>0?Result.ok("更新成功"):Result.ok("更新失败");
    }


    //查询作业单商品放置位置
    @ApiOperation("查询作业单商品位置")
    @PostMapping("/inOperation/searchGoods/{id}")
    public Result searchGoods(@PathVariable Integer id){
        List<GoodsDto> goodsDtos = inOperationService.searchGoods(id);

        return Result.ok(goodsDtos);
    }


    //更新状态
    @ApiOperation("更新状态")
    @PostMapping("/inOperation/updateStatus")
    public Result updateStatus(@RequestBody InOperationVo inOperationVo){
//        inOperationService.saveGoods(inOperationVo.getInId(),inOperationVo.getStatus());
        Integer i = inOperationService.updateStatus(inOperationVo.getInId(), inOperationVo.getStatus());
        if (i==0){
            return Result.ok("商品未分配");
        } else if (i==-1){
            return Result.ok("未开始");
        } else  {
            return Result.ok("更新状态成功");
        }

    }





}
